package com

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class RecordedSimulation extends Simulation {

	val httpProtocol = http
		.baseURL("http://ns.jujinziben.com")
		.inferHtmlResources(BlackList(""".*\.css""", """.*\.js""", """.*\.ico"""), WhiteList())
		.acceptHeader("*/*")
		.acceptEncodingHeader("gzip, deflate")
		.acceptLanguageHeader("zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2")
		.userAgentHeader("Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0")

	val headers_1 = Map("Pragma" -> "no-cache")

	val headers_3 = Map(
		"Accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
		"Upgrade-Insecure-Requests" -> "1")

	val headers_14 = Map(
		"Accept" -> "application/json, text/plain, */*",
		"Content-Type" -> "application/json;charset=utf-8",
		"api-version" -> "5.0",
		"opType" -> "0")

    val uri1 = "http://adu.g-fox.cn/adu.gif"
    val uri3 = "http://detectportal.firefox.com/success.txt"

	val scn = scenario("RecordedSimulation")
		.exec(http("request_0")
			.get(uri1 + "?channelid=stub.firefox.com.cn&fxversion=58.0.2&ceversion=2017.7&ver=2_2&pk=%7B77e19135-0dbf-40a0-88ed-a576cf14b85a%7D&uk=%7B35846ddb-b9c7-430e-8095-6dbef1180865%7D&cehome=false&locale=zh-CN&age=220&default=false&defaultHttp=false&flash=&now=1519956406743"))
		.pause(3)
		.exec(http("request_1")
			.get(uri3 + "")
			.headers(headers_1)
			.resources(http("request_2")
			.get(uri3 + "")
			.headers(headers_1),
            http("request_3")
			.get("/")
			.headers(headers_3),
            http("request_4")
			.get("/web_upload/images/thumbnail/19E4D4C85E35786F09E2F8BD9B78007825946AE1423E1791.png")
			.check(status.is(404)),
            http("request_5")
			.get("/web_upload/images/thumbnail/A9BA2D742689E2AA1E008A264E9F14F6.jpg")
			.check(status.is(404)),
            http("request_6")
			.get("/web_upload/images/thumbnail/A9BA2D742689E2AA1E008A264E9F14F6.jpg")
			.check(status.is(404)),
            http("request_7")
			.get("/web_upload/images/thumbnail/19E4D4C85E35786F09E2F8BD9B78007825946AE1423E1791.png")
			.check(status.is(404)),
            http("request_8")
			.get(uri3 + "")
			.headers(headers_1),
            http("request_9")
			.get(uri3 + "")
			.headers(headers_1),
            http("request_10")
			.get(uri3 + "")
			.headers(headers_1)))
		.pause(5)
		.exec(http("request_11")
			.get("/login")
			.headers(headers_3)
			.resources(http("request_12")
			.get(uri3 + "")
			.headers(headers_1),
            http("request_13")
			.get(uri3 + "")
			.headers(headers_1)))
		.pause(8)
		.exec(http("request_14")
			.post("/api/user/login?_=1519956430723")
			.headers(headers_14)
			.body(RawFileBody("RecordedSimulation_0014_request.txt"))
			.resources(http("request_15")
			.get("/")
			.headers(headers_3),
            http("request_16")
			.get("/web_upload/images/thumbnail/19E4D4C85E35786F09E2F8BD9B78007825946AE1423E1791.png")
			.check(status.is(404)),
            http("request_17")
			.get("/web_upload/images/thumbnail/A9BA2D742689E2AA1E008A264E9F14F6.jpg")
			.check(status.is(404)),
            http("request_18")
			.get("/web_upload/images/thumbnail/19E4D4C85E35786F09E2F8BD9B78007825946AE1423E1791.png")
			.check(status.is(404)),
            http("request_19")
			.get("/web_upload/images/thumbnail/A9BA2D742689E2AA1E008A264E9F14F6.jpg")
			.check(status.is(404)),
            http("request_20")
			.get(uri3 + "")
			.headers(headers_1),
            http("request_21")
			.get(uri3 + "")
			.headers(headers_1)))

	/*
	setUp(scn.inject(atOnceUsers(10))).protocols(httpProtocol)
	*/
	setUp(scn.inject(rampUsers(10) over (10 seconds))).protocols(httpProtocol)
}